/*
  ���潻��
*/

/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include <usart.h>

#include "../bsp/bsp_usart.h"
#include "FreeRTOS.h"
#include "oled.h"
#include "usertask.h"
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
#define MONITOR_FREQ 1000u
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */

static UartRx_t Rx;

Menu_t menu = {MENU_FIRST, MENU_FIRST};
extern Euler_t angel;

/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */

void USART2_UserIRQHandler() {
  if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE) != HAL_OK) {
    __HAL_UART_CLEAR_IDLEFLAG(&huart2);
    HAL_UART_DMAStop(&huart2);
    Rx.rx_len = 128 - __HAL_DMA_GET_COUNTER(&hdma_usart2_rx);
    Rx.rx_flag = true;
  }
}

void InteractTask(void *argument) {
  (void)argument;
  const uint32_t delay_tick = osKernelGetTickFreq() / MONITOR_FREQ;
  Uart_Init(&Rx, &huart2);
		  Oled_Init();
static bool f;
  uint32_t tick = osKernelGetTickCount();
  uint32_t pretick;

  while (1) {
    /* 1s */
    if (osKernelGetTickCount() - pretick > 1000) {
      pretick = osKernelGetTickCount();
			if(f){
    Oled_Show( menu);
				f = 0;
			}
			tick += delay_tick;

			}
    }
}
